/* 
 * next_permutation()
 */

#include "../func.h"

vector<vector<int>> permute(vector<int> &nums)
{
    vector<vector<int>> result;
    sort(nums.begin(), nums.end());

    do
    {
        result.push_back(nums);
    } while (next_permutation(nums.begin(), nums.end()));
    return result;
}

void dfs(vector<int> &nums, vector<int> &path, vector<vector<int>> &result) {
    if (path.size() == nums.size()) {
        result.push_back(path);
        return;
    }

    for (auto i : nums) {
        auto pos = find(path.begin(), path.end(), i);
        if (pos == path.end()) {
            path.push_back(i);
            dfs(nums, path, result);
            path.pop_back();
        }
    }
}